package com.ruoyi.exam.service.impl;

import java.lang.reflect.Array;
import java.util.List;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.qt.domain.QtScore;
import com.ruoyi.qt.mapper.QtScoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.exam.mapper.QtExamMapper;
import com.ruoyi.exam.domain.QtExam;
import com.ruoyi.exam.service.IQtExamService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 试卷管理Service业务层处理
 * 
 * @author zqq
 * @date 2021-11-18
 */
@Service
public class QtExamServiceImpl implements IQtExamService 
{
    @Autowired
    private QtExamMapper qtExamMapper;
    @Autowired
    private QtScoreMapper qtScoreMapper;

    /**
     * 查询试卷管理
     * 
     * @param examId 试卷管理主键
     * @return 试卷管理
     */
    @Override
    public QtExam selectQtExamByExamId(String examId)
    {
        return qtExamMapper.selectQtExamByExamId(examId);
    }

    /**
     * 查询试卷管理列表
     * 
     * @param qtExam 试卷管理
     * @return 试卷管理
     */
    @Override
    public List<QtExam> selectQtExamList(QtExam qtExam)
    {
        return qtExamMapper.selectQtExamList(qtExam);
    }

    /**
     * 新增试卷管理
     * 
     * @param qtExam 试卷管理
     * @return 结果
     */
    @Override
    @Transactional
    public int insertQtExam(QtExam qtExam)
    {   String id=IdUtils.randomUUID();
        qtExam.setExamId(id);
        QtScore score =new QtScore();

        score.setExamId(id);
        String[] uids=qtExam.getExamUsers().split(",");
        for (String  uid:uids) {
            score.setScoreId(IdUtils.randomUUID());
            score.setUserId(uid);
            qtScoreMapper.insertQtScore(score);
        }
        return qtExamMapper.insertQtExam(qtExam);
    }

    /**
     * 修改试卷管理
     * 
     * @param qtExam 试卷管理
     * @return 结果
     */
    @Override
    public int updateQtExam(QtExam qtExam)
    {
        return qtExamMapper.updateQtExam(qtExam);
    }

    /**
     * 批量删除试卷管理
     * 
     * @param examIds 需要删除的试卷管理主键
     * @return 结果
     */
    @Override
    public int deleteQtExamByExamIds(String[] examIds)
    {
        return qtExamMapper.deleteQtExamByExamIds(examIds);
    }

    /**
     * 删除试卷管理信息
     * 
     * @param examId 试卷管理主键
     * @return 结果
     */
    @Override
    public int deleteQtExamByExamId(String examId)
    {
        return qtExamMapper.deleteQtExamByExamId(examId);
    }
}
